<template>
    <div>
        <div v-if="!url">Loading</div>
        <div v-else>The most star project is <a :href="url">{{name}}</a></div>
    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: "AjaxTest",
        data() {
            return {
                name: '',
                url: ''
            }
        },
        mounted() {
            // 发送 ajax 请求
            const url = "https://api.github.com/search/repositories?q=vu&sort=stars";
            axios.get(url).then(response => {
                const result = response.data;
                const item = result.items[0];
                this.url = item.html_url;
                this.name = item.name
            }).catch(error => {
                alert(error.message)
            })
        }
    }
</script>

<style scoped>

</style>